package data.goods;

import java.util.ArrayList;

import data.ListInterIterator;

public class StockRecordfind {
	private ArrayList<StockRecord> list;
	private ArrayList<StockRecord> find=new ArrayList<StockRecord>();
	
	public StockRecordfind (ListInterIterator<StockRecord> list){
		this.list=list.toArray();
	}
	
	public ListInterIterator<StockRecord> find(String key,String message){
		if(key.equals("type")){
			findbytype(message);
		}
		else if(key.equals("date")){
			findbydate(message);
		}
		else if(key.equals("exportID")){
			findbyexportID(message);
		}
		return new ListInterIterator<StockRecord>(find);
	}
	
	private void findbytype(String message){
		for(int i=0;i<list.size();i++){
			if(String.valueOf(list.get(i).getType()).equals(message)){
				find.add(list.get(i));
			}
		}
	}
	
	private void findbydate(String message){
		for(int i=0;i<list.size();i++){
			if(list.get(i).getDate().equals(message)){
				find.add(list.get(i));
			}
		}
	}
	
	private void findbyexportID(String message){
		for(int i=0;i<list.size();i++){
			if(String.valueOf(list.get(i).getExportID()).equals(message)){
				find.add(list.get(i));
			}
		}
	}
}
